﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

/// <summary>
/// LongTextInput is used for obtaining a multi-line note or description from user.
/// This note is accessible via Text property
/// Also offers validation group and Required property which causes validation.
/// </summary>
public partial class LongTextInput : ScrumInput
{
    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void Page_Load(object sender, EventArgs e)
    {
        this.RequiredFieldValidatorInput.ErrorMessage = String.Format((string)GetLocalResourceObject("RequiredFieldError"),FieldLabel.Text);
    }

    /// <summary>
    /// Gets or sets number of rows which will be visible after loading of this control.
    /// </summary>
    /// <value>The rows.</value>
    public int Rows 
    {
        get
        {
            return this.FieldInput.Rows;
        }
        set
        {
            this.FieldInput.Rows = value;
        }
    }

    #region [Validation]

    /// <summary>
    /// Gets or sets the validation group for input
    /// </summary>
    /// <value>The validation group.</value>
    public override string ValidationGroup
    {
        get
        {
            return validationGroup;
        }
        set
        {
            validationGroup = value;
            this.RequiredFieldValidatorInput.ValidationGroup = validationGroup;
            this.FieldInput.ValidationGroup = validationGroup;
        }
    }
    /// <summary>
    /// Indication if the field is reguired
    /// </summary>
    private bool required;

    /// <summary>
    /// Gets or sets a value indicating whether this <see cref="ShortTextInput"/> is required.
    /// </summary>
    /// <value><c>true</c> if required; otherwise, <c>false</c>.</value>
    public bool Required
    {
        get
        {
            return this.required;
        }
        set
        {
            this.RequiredFieldValidatorInput.ControlToValidate = value ? this.FieldInput.ID : this.FakeTextBox.ID;
            required = value;
        }
    }

    /// <summary>
    /// Gets or sets the error message.
    /// </summary>
    /// <value>The error message.</value>
    public string ErrorMessage
    {
        get { return this.RequiredFieldValidatorInput.ErrorMessage; }
        set { this.RequiredFieldValidatorInput.ErrorMessage = value; }
    }
    #endregion

    protected override Label GetLabel()
    {
        return this.FieldLabel;
    }

    protected override WebControl GetWebControl()
    {
        return this.FieldInput;
    }
}
